package com.tianze.tzkf.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.tianze.tzkf.R;


/**
 * Created by Zcyang on 2017/12/4 0004.
 */

public class ToastUtils {

    private static Toast toast = null;//Toast对象
    private static boolean isTest = true;

    public static void showToast(Context context, String str) {
        View view = LayoutInflater.from(context).inflate(R.layout.toast_view, null);
        TextView tvMessage = (TextView) view.findViewById(R.id.tv_message_toast);


        if (toast == null) {
            toast = new Toast(context);
            //设置Toast显示位置，居中，向 X、Y轴偏移量均为0
            toast.setGravity(Gravity.BOTTOM, 0, 100);
            //获取自定义视图
            //设置文本
            tvMessage.setText(str);
            //设置视图
            toast.setView(view);
            //设置显示时长
            toast.setDuration(Toast.LENGTH_LONG);
        } else {
            //设置Toast显示位置，居中，向 X、Y轴偏移量均为0
            toast.setGravity(Gravity.BOTTOM, 0, 100);
            //获取自定义视图
            //设置文本
            tvMessage.setText(str);
            //设置视图
            toast.setView(view);
            //设置显示时长
            toast.setDuration(Toast.LENGTH_LONG);
        }
        toast.show();
    }

    public static void showTestToast(Context context, String str) {
        if (isTest) {
            if (toast == null) {
                toast = Toast.makeText(context, str, Toast.LENGTH_LONG);
            } else {
                toast.setText(str);
            }
            toast.show();
        }
    }


}
